package com.tangyuan.controller;


import com.tangyuan.common.result.Result;
import com.tangyuan.common.util.CommStatus;
import com.tangyuan.model.User;
import com.tangyuan.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 小梁
 * @since 2020-12-03
 */
@RestController
@RequestMapping("/recommend")
public class MovieController {

    @Autowired
    MovieService movieService;



    @PostMapping("/getRecommend")
    public Result<Object> getRecommend(@RequestHeader(required = false)  Long userId, @RequestParam Integer index) {
        return Result.ok(movieService.getRecommend(userId,index,10));
    }

    @GetMapping("/getConcern")
    public Result<Object> getConcern(@RequestHeader(name = "userId", required = false) Long userId,
                                     @RequestParam Integer pageNum,
                                     @RequestParam Integer pageSize) {
        return Result.ok(movieService.getConcern(userId,pageNum,pageSize));
    }

    @GetMapping("/getSameCity")
    public Result<Object> getSameCity(@RequestHeader(name = "userId", required = false) Long userId,
                                     @RequestParam(required = false) BigDecimal longitude,
                                     @RequestParam(required = false) BigDecimal latitude,
                                     @RequestParam Integer pageNum,
                                     @RequestParam Integer pageSize) {
        return Result.ok(movieService.getSameCity(userId, longitude, latitude, pageNum, pageSize));
    }

    @PostMapping("/getItemRecommend")
    public Result getItemRecommend(@RequestParam Long userId, @RequestParam Integer index) {
        return movieService.getItemRecommend(userId,index);
    }

    @GetMapping("/getMovieByRecord")
    public Result<Object> getMovieByRecord(@RequestHeader(name = "Authorization", required = false) String token,
                                           @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        User user = CommStatus.getUser(token);
        return Result.ok(movieService.getMovieByRecord(pageNum, pageSize, user));
    }

}

